package com.founder.chd_daily_query.controller;

import com.founder.chd_daily_query.entity.file.FileLoadEntity;
import com.founder.chd_daily_query.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("file")
public class FileController {

    @Autowired
    FileService fileService;


    @GetMapping("/download/{fileId}")
    public String fileDownload(@PathVariable("fileId") String fileId, HttpServletResponse httpServletResponse) throws IOException {
        return fileService.fileDownload(fileId,httpServletResponse);
    }

    @GetMapping("/list/{page}/{num}")
    public Map<String,Object> fileDownload(@PathVariable("page") int page, @PathVariable("num") int num){
        return fileService.getList(page,num);
    }

    @PostMapping("/upload")
    public Map<String,Object> fileUpload (@RequestParam("file") MultipartFile multipartFile){
        return fileService.fileUpload(multipartFile);
    }

    @GetMapping("/delete/{id}")
    public String fileDelete(@PathVariable("id") String id){
        return fileService.fileDelete(id);
    }
}
